<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page language="java" import="com.soft.model.*"%>
<%@ page language="java" import="java.util.*"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link rel="stylesheet" href="../../css/index.css" />
<link rel="stylesheet" href="../../css/common.css" />
<script type="text/javascript" src="../../js/jquery-3.3.1.js"></script>
<script type="text/javascript" src="../../js/common.js" /></script>
<script type="text/javascript" src="../../js/admin/ready.js" /></script>
<script type="application/javascript">
	$(document).ready(function() {
		
		$("#insert").click(function(event) {
			window.location.href="city_add";
		});
		
		$(".update").click(function(event) {
			console.log(event.currentTarget.name);
			var id = $(this).attr("selectedId");
			window.location.href="city_upd?id="+id;
		});
		
		
		$(".delete").click(function(event) {
			
			var id = $(this).attr("selectedId");
			console.log(event.currentTarget.name);
			showMessage("I", "您确定要删除这个记录吗？", function() {
				$.ajax({
					url:"city_del",
					data:"delIds="+id,
					type:"post",
					success:function(data){
						if(data == "ok"){
							//row.remove();
							$("#search").submit();
						}
					}
				});
				//window.location.href="city_del?id="+id;
			});
		});
		
		
		//分页
		$(".page-c .button-get").click(function(event){
			var page = $(this).text();
			$("#currPage").val(page);
			$("#search").submit();
		});
		//全选
		$("#checkAll").click(function(event){
			var isChecked = $(this).prop("checked");
			if(isChecked){
				$("input[name='checkIds']").prop("checked",true);
			}else{
				$("input[name='checkIds']").prop("checked",false);
			}
		});
		//批量删除
		$("#checkDel").click(function(event){
			showMessage("I", "您确定要删除这些记录吗？", function() {
				var ids = $("input[name='checkIds']:checked");
				var delIds = "";
				$.each(ids,function(){
					delIds+= $(this).val()+","
				});
				$.post("city_del",{delIds : delIds},function(data){
					if(data="ok"){
						//$(ids).parent().parent().remove();
						$("#search").submit();
					}
				});
			});
		});
	});
	
	var getDataByPage = function(pageInfo) {
		console.log(pageInfo);
	}
		
</script>
</head>
<body class="content-body">
	<div class="title-area bg-color-black font-normal font-white">乌托邦别墅预定管理平台>内容管理>城市管理</div>
	<div class="search-area bg-color-gray">
		<form id="search" style="float:left;" action="city_list" method="post">
			<input type="hidden" id="currPage" name="currPage" value="1"/>
			<input class="row-item bg-color-white search-input" type="text" id="searchText" name="searchText" placeholder="请输入名称" value="${searchText}" />
			<input class="row-item bg-color-white search-input" type="date" id="beginTime" name="beginTime"  value="${beginTime}" />
			<span style="font-size: small; margin-left: 5px;">-</span>
			<input class="row-item bg-color-white search-input" type="date" id="endTime" name="endTime"  value="${endTime}" />
			<button class="button-get button-item"  >查询</button>
		</form>
		 <span class="button-put button-item" id="insert">新增</span>
		 <span class="button-del button-item" id="checkDel">批量删除</span>
	</div>

	<!-- city list -->
	<div class="table bg-color-gray">
		<div class="row">
			<div class="col-half">
				<div class="grid-title"><input type="checkbox" id="checkAll">ID</div>
			</div>
			<div class="col-1">
				<div class="grid-title">城市名</div>
			</div>
			<div class="col-1">
				<div class="grid-title">所在省</div>
			</div>
			<div class="col-1">
				<div class="grid-title">添加用户</div>
			</div>
			<!-- 				<div class="col-2"><div class="grid-title">角色</div></div> -->
			<div class="col-2">
				<div class="grid-title">添加时间</div>
			</div>
			<div class="col-3">
				<div class="grid-title">操作</div>
			</div>
		</div>
		<%
			List<City> list_city = (List<City>) request.getAttribute("list_city");
			if (list_city != null && list_city.size() > 0) {
				for (City city : list_city) {
					pageContext.setAttribute("city", city);
		%>
		<div class="row row-border">
			<div class="col-half">
				<div class="grid-label"><input type="checkbox" name="checkIds" value="${city.id}">${city.id}</div>
			</div>
			<div class="col-1">
				<div class="grid-label">${city.cityname}</div>
			</div>
			<div class="col-1">
				<div class="grid-label">${city.province}</div>
			</div>
			<div class="col-1">
				<div class="grid-label">${city.adduser}</div>
			</div>
			<div class="col-2">
				<div class="grid-label">${city.addtime}</div>
			</div>
			<div class="col-3">
				<div class="update width-two grid-button button-put"
					selectedId="${city.id}">编辑</div>
				<div class="delete width-two grid-button button-del"
					selectedId="${city.id}">删除</div>
			</div>
		</div>
		<%
			}
			}
		%>
	</div>

	<!-- page_area -->
	<div class="page-area">
		<div option="front" class="option font-small font-white button-get"><<</div>
		<div class="page-list">
			<div class="page-c">
				<%	
				int pageCount = (int) request.getAttribute("pageCount");
				String pageStr= (String)request.getAttribute("currPage");
				int currPage = pageStr==null?1:Integer.parseInt(pageStr);
				for (int i = 1; i <= pageCount; i++) {
					String addClass="";
					if(i==currPage){
						addClass="selected-item";
					}
				%>
					<div target-page="<%=i%5 %>" class="item font-small font-white button-get <%=addClass %>"><%=i %></div>
				<% }%>
			</div>
		</div>
		<div option="back" class="option font-small font-white button-get">>></div>
	</div>
	<span style="color: blue;font-size: 16px;">共${totalCount}条记录</span>
</body>
</html>